package main

import (
	"log"
	"onet"
)

type Server struct{}

func (s Server) OnOpen(c onet.Conn) {
	log.Printf("connection open: %s\n", c.RemoteAddr().String())
}

func (s Server) OnData(c onet.Conn) {
	buf, _ := c.Next(-1)
	log.Printf("data received: % x\n", buf)
}

func (s Server) OnClose(c onet.Conn, err error) {
	log.Printf("connection close: %s, %s\n", c.RemoteAddr().String(), err)
}

func main() {
	server := &Server{}
	err := onet.Run(
		server, "tcp4://:9999",
		onet.WithReuseAddr(true),
		onet.WithReusePort(true),
	)
	log.Println(err)
}
